package componenthasservice;

import org.eclipse.emf.ecore.EObject;

import org.eclipse.viatra2.emf.incquery.validation.runtime.Constraint;
import org.eclipse.viatra2.emf.incquery.validation.runtime.ValidationUtil;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BaseGeneratedMatcherFactory;
import componenthasservice.ComponentHasServiceMatch;
import componenthasservice.ComponentHasServiceMatcherFactory;
import componenthasservice.ComponentHasServiceMatcher;

public class ComponentHasServiceConstraint extends Constraint<ComponentHasServiceMatch> {

	private ComponentHasServiceMatcherFactory matcherFactory;

	public ComponentHasServiceConstraint() {
		matcherFactory = new ComponentHasServiceMatcherFactory();
	}

	@Override
	public String getMessage() {
		return "Dude, $component.name$ component should have a service!";
	}

	@Override
	public EObject getLocationObject(ComponentHasServiceMatch signature) {
		Object location = signature.get("component");
		if(location instanceof EObject){
			return (EObject) location;
		}
		return null;
	}
	
	@Override
	public int getSeverity() {
		return ValidationUtil.getSeverity("warning");
	}
	
	@Override
	public BaseGeneratedMatcherFactory<ComponentHasServiceMatch, ComponentHasServiceMatcher> getMatcherFactory() {
		return matcherFactory;
	}
}
